﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;

namespace Galaktika.BI.Silverlight.Controls.General
{
    public partial class ContextMenuItem : UserControl
    {
        public event EventHandler ItemClick;
        public ContextMenuItem(String caption)
        {
            InitializeComponent();

            StackPanel stack = new StackPanel();
            m_Text = new TextBlock();
            m_Text.Margin = new Thickness(4, 4, 4, 4);

            m_Icon = new Image();
            m_Icon.Margin = new Thickness(4, 4, 4, 4);
            m_Icon.Width = 16;
            m_Icon.Height = 16;

            btnContent.Padding = new Thickness(0, 0, 0, 0);

            Border border = new Border();
            border.Width = 1;
            border.Background = new SolidColorBrush(Colors.DarkGray);
            border.Margin = new Thickness(2, 0, 0, 0);

            stack.Orientation = Orientation.Horizontal;
            stack.Children.Add(m_Icon);
            stack.Children.Add(border);
            stack.Children.Add(m_Text);

            btnContent.Content = stack;
            btnContent.HorizontalContentAlignment = HorizontalAlignment.Left;

            m_Text.Padding = new Thickness(5, 0, 0, 0);
            m_Text.Text = caption;
        }

        Image m_Icon = null;
        TextBlock m_Text = null; 

        public BitmapImage Icon
        {
            set
            {
                m_Icon.Source = value;
            }
            get
            {
                return m_Icon.Source as BitmapImage;
            }
        }


        private void btnContent_Click(object sender, RoutedEventArgs e)
        {
            EventHandler handler = ItemClick;
            if (handler != null)
            {
                handler(this, EventArgs.Empty);
            }
        }
    }
}
